// ===================================================================
// FISIER: Source/client/root/uiInventory.py
// Blocuri OfflineShop: 16
// Fiecare bloc: 'CAUTA' = cateva linii de context existente inainte,
//               'ADAUGA' = codul sistemului (liniile originale din Sinners).
// ===================================================================

// ---------- [1] linii 19-21 (bloc #if) ----------
// CAUTA:
import constInfo
import ime
import wndMgr
import exchange
// ADAUGA (dupa liniile de mai sus):
if app.__ENABLE_NEW_OFFLINESHOP__:
	import offlineshop
	import uiNewOfflineShop
// (urmat de:)
//   
//   ITEM_MALL_BUTTON_ENABLE = True

// ---------- [2] linii 207-207 (referinta fara #if) ----------
// CAUTA:
			self.wndMoney = self.GetChild("Money")
			self.wndMoneySlot = self.GetChild("Money_Slot")
	
			self.costumeButton = self.GetChild2("CostumeButton")
// ADAUGA (dupa liniile de mai sus):
			self.offlineShopButton = self.GetChild2("OfflineShopButton")
// (urmat de:)
//   
//   			self.inventoryTab = []

// ---------- [3] linii 463-466 (bloc #if) ----------
// CAUTA:
		mouseModule.mouseController.AttachMoney(self, player.SLOT_TYPE_INVENTORY, money)

	def OnPickItem(self, count):
		itemSlotIndex = self.dlgPickMoney.itemGlobalSlotIndex
// ADAUGA (dupa liniile de mai sus):
		if app.__ENABLE_NEW_OFFLINESHOP__:
			if uiNewOfflineShop.IsBuildingShop() and uiNewOfflineShop.IsSaleSlot(player.INVENTORY, itemSlotIndex):
				chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.OFFLINESHOP_CANT_SELECT_ITEM_DURING_BUILING)
				return
// (urmat de:)
//   		selectedItemVNum = player.GetItemIndex(itemSlotIndex)
//   		mouseModule.mouseController.AttachObject(self, player.SLOT_TYPE_INVENTORY, itemSlotIndex, selectedItemVNum, count)

// ---------- [4] linii 585-588 (bloc #if) ----------
// CAUTA:
	def SetItemToolTip(self, tooltipItem):
		self.tooltipItem = tooltipItem

	def SellItem(self):
// ADAUGA (dupa liniile de mai sus):
		if app.__ENABLE_NEW_OFFLINESHOP__:
			if uiNewOfflineShop.IsBuildingShop() and uiNewOfflineShop.IsSaleSlot(player.INVENTORY, self.sellingSlotNumber):
				chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.OFFLINESHOP_CANT_SELECT_ITEM_DURING_BUILING)
				return
// (urmat de:)
//   		if self.sellingSlotitemIndex == player.GetItemIndex(self.sellingSlotNumber):
//   			if self.sellingSlotitemCount == player.GetItemCount(self.sellingSlotNumber):

// ---------- [5] linii 624-627 (bloc #if) ----------
// CAUTA:
			attachedSlotType = mouseModule.mouseController.GetAttachedType()
			attachedSlotPos = mouseModule.mouseController.GetAttachedSlotNumber()
			attachedItemIndex = mouseModule.mouseController.GetAttachedItemIndex()
			attachedCount = mouseModule.mouseController.GetAttachedItemCount()
// ADAUGA (dupa liniile de mai sus):
			if app.__ENABLE_NEW_OFFLINESHOP__:
				if uiNewOfflineShop.IsBuildingShop() and uiNewOfflineShop.IsSaleSlot(player.SlotTypeToInvenType(attachedSlotType),attachedSlotPos):
					chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.OFFLINESHOP_CANT_SELECT_ITEM_DURING_BUILING)
					return
// (urmat de:)
//   			if player.SLOT_TYPE_INVENTORY == attachedSlotType:
//   				attachedCount = mouseModule.mouseController.GetAttachedItemCount()

// ---------- [6] linii 746-749 (bloc #if) ----------
// CAUTA:
	def __DropSrcItemToDestItemInInventory(self, srcItemVID, srcItemSlotPos, dstItemSlotPos, attachedSlotType):
		if srcItemSlotPos == dstItemSlotPos and attachedSlotType == player.INVENTORY:
			return

// ADAUGA (dupa liniile de mai sus):
		if app.__ENABLE_NEW_OFFLINESHOP__:
			if uiNewOfflineShop.IsBuildingShop() and (uiNewOfflineShop.IsSaleSlot(player.INVENTORY, srcItemSlotPos) or uiNewOfflineShop.IsSaleSlot(player.INVENTORY , dstItemSlotPos)):
				chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.OFFLINESHOP_CANT_SELECT_ITEM_DURING_BUILING)
				return
// (urmat de:)
//   
//   		dstItemVnum = player.GetItemIndex(dstItemSlotPos)

// ---------- [7] linii 817-820 (bloc #if) ----------
// CAUTA:
				self.__SendMoveItemPacket(srcItemSlotPos, dstItemSlotPos, 0)
				#net.SendItemMovePacket(srcItemSlotPos, dstItemSlotPos, 0)

	def __SellItem(self, itemSlotPos):
// ADAUGA (dupa liniile de mai sus):
		if app.__ENABLE_NEW_OFFLINESHOP__:
			if uiNewOfflineShop.IsBuildingShop():
				chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.OFFLINESHOP_CANT_SELECT_ITEM_DURING_BUILING)
				return
// (urmat de:)
//   
//   		if not player.IsEquipmentSlot(itemSlotPos):

// ---------- [8] linii 864-867 (bloc #if) ----------
// CAUTA:
	def __OnClosePopupDialog(self):
		self.pop = None

	def RefineItem(self, scrollSlotPos, targetSlotPos, attachedSlotPos = -1):
// ADAUGA (dupa liniile de mai sus):
		if app.__ENABLE_NEW_OFFLINESHOP__:
			if uiNewOfflineShop.IsBuildingShop():
				chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.OFFLINESHOP_CANT_SELECT_ITEM_DURING_BUILING)
				return
// (urmat de:)
//   		scrollIndex = player.GetItemIndex(scrollSlotPos)
//   		targetIndex = player.GetItemIndex(targetSlotPos)

// ---------- [9] linii 1236-1238 (bloc #if) ----------
// CAUTA:
			itemVnum = player.GetItemIndex(slotIndex)
			if itemVnum != 0:
				self.tooltipItem.SetInventoryItem(slotIndex)
				self.tooltipItem.AppendEmojiForInventory(slotIndex, itemVnum)
// ADAUGA (dupa liniile de mai sus):
				if app.__ENABLE_NEW_OFFLINESHOP__:
					if uiNewOfflineShop.IsBuildingShop() or uiNewOfflineShop.IsBuildingAuction():
						self.__AddTooltipSaleMode(slotIndex)
// (urmat de:)
//   
//   	if app.__ENABLE_NEW_OFFLINESHOP__:

// ---------- [10] linii 1240-1251 (bloc #if) ----------
// CAUTA:
				if app.__ENABLE_NEW_OFFLINESHOP__:
					if uiNewOfflineShop.IsBuildingShop() or uiNewOfflineShop.IsBuildingAuction():
						self.__AddTooltipSaleMode(slotIndex)

// ADAUGA (dupa liniile de mai sus):
	if app.__ENABLE_NEW_OFFLINESHOP__:
		def __AddTooltipSaleMode(self, slot):
			if player.IsEquipmentSlot(slot):
				return

			itemIndex = player.GetItemIndex(slot)
			if itemIndex !=0:
				item.SelectItem(itemIndex)
				if item.IsAntiFlag(item.ANTIFLAG_MYSHOP) or item.IsAntiFlag(item.ANTIFLAG_GIVE):
					return

				self.tooltipItem.AddRightClickForSale()
// (urmat de:)
//   
//   	def OnTop(self):

// ---------- [11] linii 1313-1339 (bloc #if) ----------
// CAUTA:
			return

		slotIndex = self.__InventoryLocalSlotPosToGlobalSlotPos(slotIndex)

// ADAUGA (dupa liniile de mai sus):
		if app.__ENABLE_NEW_OFFLINESHOP__:
			if uiNewOfflineShop.IsBuildingShop():
				globalSlot 	= slotIndex
				itemIndex 	= player.GetItemIndex(globalSlot)

				item.SelectItem(itemIndex)

				if not item.IsAntiFlag(item.ANTIFLAG_GIVE) and not item.IsAntiFlag(item.ANTIFLAG_MYSHOP):
					offlineshop.ShopBuilding_AddInventoryItem(globalSlot)

				else:
					chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.OFFLINESHOP_CANT_SELECT_ITEM_DURING_BUILING)

				return

			elif uiNewOfflineShop.IsBuildingAuction():
				globalSlot = slotIndex
				itemIndex = player.GetItemIndex(globalSlot)

				item.SelectItem(itemIndex)

				if not item.IsAntiFlag(item.ANTIFLAG_GIVE) and not item.IsAntiFlag(item.ANTIFLAG_MYSHOP):
					offlineshop.AuctionBuilding_AddInventoryItem(globalSlot)
				else:
					chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.OFFLINESHOP_CANT_SELECT_ITEM_DURING_BUILING)

				return
// (urmat de:)
//   
//   		if app.ITEM_CHECKINOUT_UPDATE:

// ---------- [12] linii 1365-1368 (bloc #if) ----------
// CAUTA:
			return

		item.SelectItem(ItemVNum)

// ADAUGA (dupa liniile de mai sus):
		if app.__ENABLE_NEW_OFFLINESHOP__:
			if uiNewOfflineShop.IsBuildingShop() and uiNewOfflineShop.IsSaleSlot(player.INVENTORY, slotIndex):
				chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.OFFLINESHOP_CANT_SELECT_ITEM_DURING_BUILING)
				return
// (urmat de:)
//   
//   		if app.ENABLE_EASTER_EVENT:

// ---------- [13] linii 1419-1422 (bloc #if) ----------
// CAUTA:
		if uiPrivateShopBuilder.IsBuildingPrivateShop():
			chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.USE_ITEM_FAILURE_PRIVATE_SHOP)
			return

// ADAUGA (dupa liniile de mai sus):
		if app.__ENABLE_NEW_OFFLINESHOP__:
			if uiNewOfflineShop.IsBuildingShop() or uiNewOfflineShop.IsBuildingAuction():
				chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.USE_ITEM_FAILURE_PRIVATE_SHOP)
				return
// (urmat de:)
//   
//   		net.SendItemUseToItemPacket(srcSlotPos, dstSlotPos)

// ---------- [14] linii 1433-1436 (bloc #if) ----------
// CAUTA:
		if uiPrivateShopBuilder.IsBuildingPrivateShop():
			chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.USE_ITEM_FAILURE_PRIVATE_SHOP)
			return

// ADAUGA (dupa liniile de mai sus):
		if app.__ENABLE_NEW_OFFLINESHOP__:
			if uiNewOfflineShop.IsBuildingShop() or uiNewOfflineShop.IsBuildingAuction():
				chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.USE_ITEM_FAILURE_PRIVATE_SHOP)
				return
// (urmat de:)
//   
//   		net.SendItemUsePacket(slotPos)

// ---------- [15] linii 1445-1448 (bloc #if) ----------
// CAUTA:
		if uiPrivateShopBuilder.IsBuildingPrivateShop():
			chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.MOVE_ITEM_FAILURE_PRIVATE_SHOP)
			return

// ADAUGA (dupa liniile de mai sus):
		if app.__ENABLE_NEW_OFFLINESHOP__:
			if uiNewOfflineShop.IsBuildingShop() or uiNewOfflineShop.IsBuildingAuction():
				chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.MOVE_ITEM_FAILURE_PRIVATE_SHOP)
				return
// (urmat de:)
//   
//   		net.SendItemMovePacket(srcSlotPos, dstSlotPos, srcItemCount)

// ---------- [16] linii 1472-1474 (bloc #if) ----------
// CAUTA:
		self.questionDialog.Open()

	def __Sort(self):
		self.OnCloseQuestionDialog()
// ADAUGA (dupa liniile de mai sus):
		if app.__ENABLE_NEW_OFFLINESHOP__:
			if uiNewOfflineShop.IsBuildingShop() or uiNewOfflineShop.IsBuildingAuction():
				return
// (urmat de:)
//   
//   		net.SendChatPacket("/sortinv")

